package cn.itrip.service.impl;

import cn.itrip.entity.ItripTradeEnds;
import cn.itrip.dao.ItripTradeEndsDao;
import cn.itrip.service.ItripTradeEndsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 订单支付完成后，系统需对该订单进行后续处理，如减库存等。处理完成后，删除此表中的订单记录(ItripTradeEnds)表服务实现类
 *
 * @author makejava
 * @since 2022-04-14 22:34:59
 */
@Service("itripTradeEndsService")
public class ItripTradeEndsServiceImpl implements ItripTradeEndsService {
	@Resource
	private ItripTradeEndsDao itripTradeEndsDao;

	/**
	 * 通过ID查询单条数据
	 *
	 * @param id 主键
	 * @return 实例对象
	 */
	@Override
	public ItripTradeEnds queryById(Long id) {
		return this.itripTradeEndsDao.queryById(id);
	}

	/**
	 * 分页查询
	 *
	 * @param itripTradeEnds 筛选条件
	 * @param pageRequest    分页对象
	 * @return 查询结果
	 */
	@Override
	public Page<ItripTradeEnds> queryByPage(ItripTradeEnds itripTradeEnds, PageRequest pageRequest) {
		long total = this.itripTradeEndsDao.count(itripTradeEnds);
		return new PageImpl<>(this.itripTradeEndsDao.queryAllByLimit(itripTradeEnds, pageRequest), pageRequest, total);
	}

	/**
	 * 新增数据
	 *
	 * @param itripTradeEnds 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripTradeEnds insert(ItripTradeEnds itripTradeEnds) {
		this.itripTradeEndsDao.insert(itripTradeEnds);
		return itripTradeEnds;
	}

	/**
	 * 修改数据
	 *
	 * @param itripTradeEnds 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripTradeEnds update(ItripTradeEnds itripTradeEnds) {
		this.itripTradeEndsDao.update(itripTradeEnds);
		return this.queryById(itripTradeEnds.getId());
	}

	/**
	 * 通过主键删除数据
	 *
	 * @param id 主键
	 * @return 是否成功
	 */
	@Override
	public boolean deleteById(Long id) {
		return this.itripTradeEndsDao.deleteById(id) > 0;
	}
}
